{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os \n",
    "import re\n",
    "import numpy as np\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "data ={\n",
    "    'docs':[],\n",
    "    'labels':[]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['ham', 'spam']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.listdir('email')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1.txt',\n",
       " '10.txt',\n",
       " '11.txt',\n",
       " '12.txt',\n",
       " '13.txt',\n",
       " '14.txt',\n",
       " '15.txt',\n",
       " '16.txt',\n",
       " '17.txt',\n",
       " '18.txt',\n",
       " '19.txt',\n",
       " '2.txt',\n",
       " '20.txt',\n",
       " '21.txt',\n",
       " '22.txt',\n",
       " '23.txt',\n",
       " '24.txt',\n",
       " '25.txt',\n",
       " '3.txt',\n",
       " '4.txt',\n",
       " '5.txt',\n",
       " '6.txt',\n",
       " '7.txt',\n",
       " '8.txt',\n",
       " '9.txt']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.listdir('email/spam')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def readTxt():\n",
    "    #局部变量\n",
    "    docs=[]\n",
    "    labels=[]\n",
    "    for label in os.listdir('email'):\n",
    "        for filename in os.listdir('email/'+label):\n",
    "            doc = open('email/'+label+'/'+filename,errors='ignore').read()\n",
    "            #数据切分\n",
    "            doc = [tok.lower() for tok in re.split(r'\\W',doc) if len(tok)>1]\n",
    "            docs.append(doc)\n",
    "            labels.append(label)\n",
    "\n",
    "    return docs,labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['docs'][:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "open('email/spam/1.txt',errors='ignore').read()\n",
    "\n",
    "data['docs'],data['labels']= readTxt()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getDocList(docs):\n",
    "    docSet = set([])\n",
    "    for doc in docs:\n",
    "        docSet = set(doc) | docSet\n",
    "    doclist = list(docSet)\n",
    "    doclist.sort()\n",
    "    return doclist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "748"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(getDocList(data['docs']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "docList = getDocList(data['docs'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def doc2V(doc,doclist):\n",
    "    #单词集合的维度\n",
    "    dims = len(doclist)\n",
    "    #初始化 坐标点\n",
    "    doc_v= [0]*dims\n",
    "\n",
    "    for word in doc:\n",
    "        if word in doclist:\n",
    "            doc_v[doclist.index(word)] +=1\n",
    "    return doc_v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "docs_v = list(map(lambda doc: doc2V(doc,docList),data['docs']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 2,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 2,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "docs_v[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "def train(docs_v,labels,docList):\n",
    "    #Abusive\n",
    "    n_doc = len(labels)\n",
    "    #向量基 永远是 docList\n",
    "    docLen = len(docList)\n",
    "    p1num = np.ones(docLen)\n",
    "    p0num = np.ones(docLen)\n",
    "    p1Denom,p0Denom =2,2\n",
    "\n",
    "    for i in range(n_doc):\n",
    "        if labels[i]=='spam':\n",
    "            p1num += docs_v[i]\n",
    "            p1Denom += np.sum(docs_v[i])\n",
    "        elif labels[i]=='ham':\n",
    "            p0num += docs_v[i]\n",
    "            p0Denom += np.sum(docs_v[i])    \n",
    "\n",
    "    return np.log(p1num/p1Denom),np.log(p0num/p0Denom),labels.count('spam')/n_doc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "p1doc,p0doc,pA = train(docs_v,data['labels'],docList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([-4.33477375, -5.80111082, -4.95381296, -3.53242728, -6.89972311,\n",
       "        -6.20657593, -6.20657593, -6.89972311, -6.20657593, -4.82028157,\n",
       "        -5.80111082, -5.80111082, -6.20657593, -6.89972311, -6.20657593,\n",
       "        -6.20657593, -4.50182783, -6.89972311, -5.51342875, -6.89972311,\n",
       "        -5.80111082, -5.80111082, -5.80111082, -6.20657593, -6.20657593,\n",
       "        -6.20657593, -6.89972311, -5.29028519, -5.80111082, -5.80111082,\n",
       "        -5.80111082, -6.20657593, -6.20657593, -5.80111082, -3.80868065,\n",
       "        -6.89972311, -4.95381296, -6.20657593, -6.20657593, -5.80111082,\n",
       "        -5.80111082, -6.20657593, -5.80111082, -6.20657593, -6.20657593,\n",
       "        -6.20657593, -6.20657593, -4.95381296, -6.89972311, -6.20657593,\n",
       "        -5.80111082, -5.80111082, -5.80111082, -6.20657593, -6.20657593,\n",
       "        -4.95381296, -5.80111082, -6.89972311, -5.29028519, -4.70249853,\n",
       "        -5.80111082, -5.51342875, -6.89972311, -6.89972311, -4.59713801,\n",
       "        -6.89972311, -6.89972311, -5.51342875, -5.80111082, -6.89972311,\n",
       "        -6.20657593, -6.89972311, -6.89972311, -5.51342875, -6.89972311,\n",
       "        -6.89972311, -5.10796364, -6.89972311, -6.89972311, -4.82028157,\n",
       "        -6.20657593, -6.20657593, -6.89972311, -5.80111082, -3.90399083,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -5.51342875,\n",
       "        -6.89972311, -5.80111082, -6.89972311, -5.51342875, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -4.70249853, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -4.95381296, -5.80111082, -6.20657593,\n",
       "        -6.89972311, -6.20657593, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -4.82028157, -6.20657593,\n",
       "        -6.20657593, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -5.51342875, -4.95381296,\n",
       "        -6.20657593, -6.20657593, -6.89972311, -6.89972311, -4.41481646,\n",
       "        -6.20657593, -5.80111082, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -5.51342875, -6.89972311, -6.89972311, -6.89972311, -5.51342875,\n",
       "        -6.89972311, -6.89972311, -5.51342875, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.20657593, -6.20657593, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -5.80111082, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -5.51342875, -6.89972311,\n",
       "        -6.89972311, -4.59713801, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -4.82028157,\n",
       "        -6.89972311, -6.89972311, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -5.51342875, -6.89972311, -6.89972311, -6.89972311, -5.51342875,\n",
       "        -6.20657593, -6.89972311, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -6.89972311, -6.89972311, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -4.82028157, -6.89972311, -5.51342875, -6.89972311, -6.89972311,\n",
       "        -5.51342875, -5.51342875, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -4.82028157, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.20657593, -6.20657593, -6.89972311,\n",
       "        -6.20657593, -6.89972311, -4.95381296, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.20657593, -6.89972311, -6.89972311, -5.80111082,\n",
       "        -6.89972311, -6.89972311, -5.51342875, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -4.82028157, -5.51342875, -6.89972311, -5.80111082,\n",
       "        -6.89972311, -4.82028157, -6.89972311, -6.89972311, -4.70249853,\n",
       "        -6.89972311, -6.20657593, -4.82028157, -6.89972311, -5.51342875,\n",
       "        -5.80111082, -5.51342875, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -5.80111082,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -5.29028519, -6.20657593,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.20657593, -6.20657593, -6.20657593, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -4.33477375,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -5.51342875,\n",
       "        -5.29028519, -5.51342875, -6.89972311, -6.89972311, -4.82028157,\n",
       "        -4.82028157, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -5.80111082, -6.89972311, -5.51342875, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.20657593, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.20657593, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.20657593, -5.80111082, -5.51342875, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -4.82028157,\n",
       "        -6.89972311, -4.59713801, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -4.82028157, -5.29028519, -5.51342875,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -5.80111082, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.20657593, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -4.19167291, -4.70249853, -6.89972311, -6.20657593,\n",
       "        -6.89972311, -6.89972311, -4.19167291, -4.82028157, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -4.82028157, -6.89972311, -6.89972311, -5.10796364,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -5.51342875, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -4.82028157, -6.20657593, -6.89972311, -6.20657593,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -5.51342875, -5.80111082, -6.89972311,\n",
       "        -5.80111082, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -5.51342875, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -5.80111082,\n",
       "        -4.33477375, -5.51342875, -6.89972311, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -5.80111082, -5.80111082, -6.89972311, -6.20657593,\n",
       "        -5.80111082, -6.89972311, -4.95381296, -5.80111082, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -5.29028519,\n",
       "        -4.82028157, -5.80111082, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -6.20657593, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -5.51342875, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -4.19167291,\n",
       "        -6.20657593, -4.82028157, -5.29028519, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -6.20657593, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -4.82028157, -4.95381296, -5.80111082, -6.20657593, -6.89972311,\n",
       "        -4.95381296, -5.80111082, -5.51342875, -6.89972311, -6.89972311,\n",
       "        -6.20657593, -6.89972311, -6.89972311, -6.89972311, -5.80111082,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -4.95381296, -6.89972311, -4.82028157, -6.89972311, -5.51342875,\n",
       "        -5.29028519, -6.89972311, -6.20657593, -6.89972311, -6.89972311,\n",
       "        -5.80111082, -4.50182783, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.20657593, -5.80111082, -6.89972311,\n",
       "        -5.80111082, -6.20657593, -6.20657593, -5.80111082, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -5.10796364, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -5.51342875, -6.89972311, -6.89972311,\n",
       "        -5.80111082, -6.89972311, -6.89972311, -5.51342875, -6.89972311,\n",
       "        -5.51342875, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -4.82028157, -6.89972311, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -4.59713801, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -4.95381296, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -5.51342875, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.20657593, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -5.51342875, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -5.80111082, -6.20657593, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -5.80111082, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -5.80111082, -5.29028519, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -4.82028157,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -6.89972311, -6.89972311, -6.20657593, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -5.51342875, -6.20657593, -6.20657593, -3.4657359 ,\n",
       "        -5.51342875, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -5.80111082, -6.89972311, -6.89972311, -6.89972311, -6.20657593,\n",
       "        -5.80111082, -6.89972311, -6.89972311, -6.20657593, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.20657593, -4.41481646,\n",
       "        -6.89972311, -6.89972311, -5.51342875, -6.89972311, -5.80111082,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -5.51342875, -6.20657593,\n",
       "        -5.80111082, -6.89972311, -4.82028157, -6.89972311, -4.82028157,\n",
       "        -5.51342875, -5.51342875, -6.89972311, -5.51342875, -6.89972311,\n",
       "        -6.89972311, -4.82028157, -5.51342875, -5.51342875, -6.89972311,\n",
       "        -5.51342875, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -5.80111082, -6.89972311, -5.51342875,\n",
       "        -6.89972311, -5.29028519, -6.89972311, -5.80111082, -6.89972311,\n",
       "        -5.80111082, -5.80111082, -6.20657593, -6.89972311, -5.80111082,\n",
       "        -6.20657593, -6.89972311, -6.89972311, -6.89972311, -6.89972311,\n",
       "        -6.20657593, -6.89972311, -6.89972311, -5.51342875, -6.89972311,\n",
       "        -6.89972311, -6.89972311, -4.41481646, -4.82028157, -4.19167291,\n",
       "        -6.89972311, -6.89972311, -6.20657593]),\n",
       " array([-6.39191711, -7.08506429, -6.39191711, -7.08506429, -6.39191711,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -7.08506429, -5.98645201,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -7.08506429, -7.08506429,\n",
       "        -5.69876993, -6.39191711, -7.08506429, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -7.08506429, -7.08506429,\n",
       "        -6.39191711, -7.08506429, -7.08506429, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -5.98645201, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -5.47562638, -5.98645201, -7.08506429, -5.69876993,\n",
       "        -7.08506429, -5.69876993, -6.39191711, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -5.47562638, -5.98645201, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -5.29330482, -7.08506429, -3.75285978,\n",
       "        -6.39191711, -6.39191711, -4.68716902, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -7.08506429, -4.60015764, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -5.98645201, -5.47562638, -6.39191711, -6.39191711,\n",
       "        -4.88783972, -6.39191711, -6.39191711, -5.98645201, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -7.08506429, -7.08506429,\n",
       "        -6.39191711, -5.00562275, -6.39191711, -5.98645201, -6.39191711,\n",
       "        -5.98645201, -5.98645201, -5.69876993, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -6.39191711, -5.29330482, -6.39191711, -5.69876993,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -5.69876993, -6.39191711, -6.39191711, -4.68716902,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -5.98645201, -7.08506429, -6.39191711,\n",
       "        -5.47562638, -7.08506429, -5.98645201, -6.39191711, -5.13915414,\n",
       "        -5.47562638, -5.69876993, -5.47562638, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -5.98645201, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -5.69876993, -6.39191711,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -5.98645201, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -6.39191711, -5.69876993,\n",
       "        -5.29330482, -7.08506429, -6.39191711, -6.39191711, -5.98645201,\n",
       "        -6.39191711, -5.98645201, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -5.98645201, -6.39191711, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -5.98645201, -5.47562638, -7.08506429, -5.29330482, -5.69876993,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -5.98645201, -7.08506429,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -7.08506429, -7.08506429, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -5.98645201, -6.39191711, -7.08506429, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -5.13915414, -6.39191711,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -4.60015764,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -4.7824792 , -7.08506429, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -5.98645201, -6.39191711,\n",
       "        -7.08506429, -6.39191711, -5.47562638, -5.98645201, -6.39191711,\n",
       "        -6.39191711, -5.69876993, -5.47562638, -5.29330482, -4.52011494,\n",
       "        -5.69876993, -5.47562638, -7.08506429, -6.39191711, -5.47562638,\n",
       "        -5.47562638, -7.08506429, -7.08506429, -7.08506429, -6.39191711,\n",
       "        -5.98645201, -5.98645201, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -5.29330482, -5.13915414, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -7.08506429,\n",
       "        -5.13915414, -6.39191711, -5.98645201, -5.29330482, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -5.98645201, -5.13915414,\n",
       "        -6.39191711, -7.08506429, -5.98645201, -5.47562638, -6.39191711,\n",
       "        -6.39191711, -4.52011494, -7.08506429, -6.39191711, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -5.98645201, -6.39191711, -4.88783972,\n",
       "        -6.39191711, -4.52011494, -6.39191711, -6.39191711, -5.98645201,\n",
       "        -5.98645201, -7.08506429, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -5.98645201, -6.39191711, -5.98645201,\n",
       "        -5.69876993, -6.39191711, -5.98645201, -6.39191711, -7.08506429,\n",
       "        -5.47562638, -5.98645201, -6.39191711, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -5.98645201, -6.39191711, -7.08506429,\n",
       "        -5.47562638, -6.39191711, -6.39191711, -5.29330482, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -5.98645201, -7.08506429, -7.08506429, -6.39191711,\n",
       "        -7.08506429, -6.39191711, -5.98645201, -5.98645201, -6.39191711,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -6.39191711, -5.47562638,\n",
       "        -6.39191711, -6.39191711, -5.98645201, -6.39191711, -5.29330482,\n",
       "        -6.39191711, -5.98645201, -5.98645201, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -7.08506429, -5.47562638,\n",
       "        -6.39191711, -7.08506429, -7.08506429, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -6.39191711, -5.69876993, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -5.29330482, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -5.98645201, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -6.39191711, -5.47562638, -6.39191711, -5.98645201,\n",
       "        -7.08506429, -5.29330482, -5.98645201, -6.39191711, -5.69876993,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -7.08506429, -4.25185095,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -3.82696776, -6.39191711, -5.29330482, -5.98645201,\n",
       "        -5.69876993, -5.69876993, -7.08506429, -7.08506429, -5.13915414,\n",
       "        -7.08506429, -7.08506429, -7.08506429, -6.39191711, -5.98645201,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -5.69876993, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -6.39191711, -7.08506429, -5.00562275, -7.08506429,\n",
       "        -7.08506429, -5.98645201, -7.08506429, -6.39191711, -5.98645201,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -5.47562638, -6.39191711, -6.39191711, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -5.69876993,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -5.29330482,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -7.08506429, -6.39191711, -5.69876993, -7.08506429, -5.69876993,\n",
       "        -6.39191711, -5.98645201, -6.39191711, -6.39191711, -5.98645201,\n",
       "        -5.98645201, -7.08506429, -6.39191711, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -5.98645201, -7.08506429, -7.08506429, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -5.98645201, -6.39191711,\n",
       "        -5.69876993, -5.69876993, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -5.98645201, -6.39191711,\n",
       "        -5.98645201, -7.08506429, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -5.69876993, -5.47562638, -6.39191711,\n",
       "        -6.39191711, -5.69876993, -7.08506429, -5.69876993, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -5.69876993, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -6.39191711, -6.39191711, -5.13915414,\n",
       "        -6.39191711, -6.39191711, -5.00562275, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -5.98645201, -6.39191711, -7.08506429, -5.98645201,\n",
       "        -6.39191711, -7.08506429, -7.08506429, -5.29330482, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -5.98645201, -5.98645201,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -5.98645201, -6.39191711, -4.31247557, -3.23491669, -5.69876993,\n",
       "        -6.39191711, -5.13915414, -5.47562638, -5.47562638, -7.08506429,\n",
       "        -6.39191711, -6.39191711, -5.98645201, -6.39191711, -4.37701409,\n",
       "        -5.98645201, -5.98645201, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -7.08506429, -5.69876993, -7.08506429, -3.39618484,\n",
       "        -5.98645201, -6.39191711, -6.39191711, -5.98645201, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -7.08506429, -5.98645201,\n",
       "        -6.39191711, -6.39191711, -6.39191711, -7.08506429, -5.69876993,\n",
       "        -6.39191711, -5.98645201, -7.08506429, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -5.98645201, -5.98645201, -7.08506429, -7.08506429,\n",
       "        -7.08506429, -5.98645201, -7.08506429, -6.39191711, -7.08506429,\n",
       "        -7.08506429, -7.08506429, -6.39191711, -7.08506429, -5.00562275,\n",
       "        -6.39191711, -7.08506429, -7.08506429, -7.08506429, -5.98645201,\n",
       "        -4.31247557, -6.39191711, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -5.69876993, -5.98645201, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -7.08506429, -6.39191711, -5.00562275,\n",
       "        -5.69876993, -7.08506429, -5.98645201, -6.39191711, -6.39191711,\n",
       "        -4.7824792 , -7.08506429, -5.98645201, -5.98645201, -7.08506429,\n",
       "        -7.08506429, -5.98645201, -6.39191711, -5.47562638, -5.69876993,\n",
       "        -7.08506429, -6.39191711, -6.39191711, -6.39191711, -6.39191711,\n",
       "        -6.39191711, -6.39191711, -3.55870377, -4.44600696, -7.08506429,\n",
       "        -6.39191711, -5.98645201, -7.08506429]),\n",
       " 0.5)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p1doc,p0doc,pA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def classify(doc,p1doc,p0doc,pA):\n",
    "    doc_v = doc2V(doc,docList)\n",
    "    p1 =np.sum(doc_v * p1doc) + np.log(pA)\n",
    "    p0 =np.sum(doc_v * p0doc) + np.log(1-pA)\n",
    "\n",
    "    if p1>p0:\n",
    "        return 'spam'\n",
    "    else:\n",
    "        return 'ham'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'spam'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "classify(data['docs'][40],p1doc,p0doc,pA)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ham'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "classify('and xxx I could'.split(' '),p1doc,p0doc,pA)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "a6dc62afd8b03c17538a9dfce2fcb18f62cec380cc7b77050462a64b7e4e4814"
  },
  "kernelspec": {
   "display_name": "Python 3.8.0 32-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
